package com.px.task.domain;

import cn.hutool.core.date.BetweenFormatter;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.px.common.annotation.Excel;
import com.px.common.core.domain.BaseEntity;
import com.px.common.config.MinIoClientConfig;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;

/**
 * 任务记录对象 task_record
 * 
 * @author WRJ
 * @date 2024-08
 */
@Data
public class TaskRecord extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** ID */
    @ApiModelProperty(value = "ID")
    private Long id;

    /** 所属计划ID */
    @ApiModelProperty(value = "所属计划ID")
    @Excel(name = "所属计划ID")
    private Long calendarId;

    /** 任务名称 */
    @ApiModelProperty(value = "任务名称")
    @Excel(name = "任务名称")
    private String taskName;

    /** 任务描述 */
    @ApiModelProperty(value = "任务描述")
    @Excel(name = "任务描述")
    private String taskDesc;

    /** 机场主键id */
    @ApiModelProperty(value = "机场ID")
    @Excel(name = "机场ID")
    private Long airportId;

    /** 机场SN */
    @ApiModelProperty(value = "机场SN")
    @Excel(name = "机场SN")
    private String airportSn;

    /** 机场名称 */
    @ApiModelProperty(value = "机场名称")
    @Excel(name = "机场名称")
    private String airportName;

    /** 机场地址 */
    @ApiModelProperty(value = "机场地址")
    @Excel(name = "机场地址")
    private String airportAddress;

    /** 机场子设备名称 */
    @ApiModelProperty(value = "机场子设备名称")
    @Excel(name = "机场子设备名称")
    private String airportChildName;

    /** 任务开始时间 */
    @ApiModelProperty(value = "任务开始时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "任务开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date taskBeginTime;

    /** 任务结束时间 */
    @ApiModelProperty(value = "任务结束时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "任务结束时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date taskEndTime;

    /** 任务状态.0=进行中,1=已结束 */
    @ApiModelProperty(value = "任务状态.0=进行中,1=已结束")
    @Excel(name = "任务状态.0=进行中,1=已结束")
    private Integer taskStatus;

    /** 结束状态.0=正常结束,1=异常结束 */
    @ApiModelProperty(value = "结束状态.0=正常结束,1=异常结束")
    @Excel(name = "结束状态.0=正常结束,1=异常结束")
    private Integer endStatus;

    /** 航线名称 */
    @ApiModelProperty(value = "航线名称")
    @Excel(name = "航线名称")
    private String routesName;

    /** 航线起点 */
    @ApiModelProperty(value = "航线起点")
    @Excel(name = "航线起点")
    private String routesStartPoint;

    /** 航线终点 */
    @ApiModelProperty(value = "航线终点")
    @Excel(name = "航线终点")
    private String routesEndPoint;

    /** 航线里程(米) */
    @ApiModelProperty(value = "航线里程(米)")
    @Excel(name = "航线里程(米)")
    private Integer routeMileage;

    /** 航线图片url */
    @ApiModelProperty(value = "航线图片url")
    @Excel(name = "航线图片url")
    private String routesUrl;

    /** 航线图片预览url */
    @ApiModelProperty(value = "航线图片预览url")
    @Excel(name = "航线图片预览url")
    private String routesPreviewUrl;

    /** 创建人所属部门 */
    private Long deptId;

    private String taskTimeStr;

    public String getTaskTimeStr(){
        if (null != taskBeginTime && null!= taskEndTime) {
            long betweenMs = DateUtil.between(taskEndTime, taskBeginTime, DateUnit.MS, true);
            return DateUtil.formatBetween(betweenMs, BetweenFormatter.Level.SECOND);
        }
        return "";
    }

    public String getRoutesPreviewUrl() {
        if (null != routesUrl && routesUrl.startsWith("http")) {
            return routesUrl;
        } else {
            return MinIoClientConfig.PREVIEW_END_POINT_URL + "/" + routesUrl;
        }
    }
}
